package com.qujia.station.controller;

import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.core.page.TableDataInfo;
import com.qujia.common.enums.BusinessType;
import com.qujia.station.domain.form.WxMessageTemplateQueryForm;
import com.qujia.station.domain.form.WxMessageTemplateForm;
import com.qujia.station.domain.vo.WxMessageTemplateQueryVo;
import com.qujia.station.service.WxMessageTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "微信模板管理")
@RestController
@RequestMapping("/wxMessageTemplate")
public class WxMessageTemplateController extends BaseController {

    @Autowired
    private WxMessageTemplateService wxMessageTemplateService;

    @Log(title = "新增微信模板", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增微信模板", notes = "新增微信模板")
    @PostMapping
    public AjaxResult add(@Valid @RequestBody WxMessageTemplateForm wxMessageTemplateForm) {
        wxMessageTemplateService.insertWxMessageTemplate(wxMessageTemplateForm);
        return AjaxResult.success();
    }

    @Log(title = "修改微信模板", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改微信模板", notes = "修改微信模板")
    @ApiImplicitParam(paramType = "path", name = "id", value = "微信模板ID", required = true)
    @PutMapping
    public AjaxResult update(@Valid @RequestBody WxMessageTemplateForm wxMessageTemplateForm) {
        wxMessageTemplateService.updateWxMessageTemplate(wxMessageTemplateForm);
        return AjaxResult.success();
    }

    @ApiOperation(value = "获取微信模板", notes = "获取微信模板")
    @ApiImplicitParam(paramType = "path", name = "enterpriseId", value = "油企ID", required = true)
    @GetMapping(value = "/{enterpriseId}")
    public AjaxResult get(@PathVariable Long enterpriseId) {
        return AjaxResult.success(wxMessageTemplateService.selectWxMessageTemplateById(enterpriseId));
    }

    @Log(title = "逻辑删除微信模板", businessType = BusinessType.DELETE)
    @ApiOperation(value = "逻辑删除微信模板", notes = "逻辑删除微信模板")
    @ApiImplicitParam(paramType = "path", name = "enterpriseIds", value = "油企ID集合，多个用','分隔", required = true)
    @DeleteMapping("/{enterpriseIds}")
    public AjaxResult delete(@PathVariable String enterpriseIds) {
        wxMessageTemplateService.deleteWxMessageTemplate(enterpriseIds);
        return AjaxResult.success();
    }

    @GetMapping("/page")
    @ApiOperation(value = "微信模板分页", notes = "微信模板分页")
    public TableDataInfo page(WxMessageTemplateQueryForm queryForm) {
        startPage();
        List<WxMessageTemplateQueryVo> wxMessageTemplateQueryVoList = wxMessageTemplateService.pageWxMessageTemplate(queryForm);
        return getDataTable(wxMessageTemplateQueryVoList);
    }

    @ApiOperation(value = "校验模板ID", notes = "校验模板ID")
    @PostMapping("/checkId")
    public AjaxResult check(@Valid @RequestBody WxMessageTemplateForm wxMessageTemplateForm) {
        return wxMessageTemplateService.checkWxMessageTemplate(wxMessageTemplateForm) ? AjaxResult.success(true) : AjaxResult.success(false);
    }
}
